#include<bits/stdc++.h>

using namespace std;

int n, m;
int x1, y1, x2, y2;
int flag = 0;

int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };

int step = 0;

char maps[1010][1010] = { 0 };

bool check[1010][1010] = { 0 };

void Bfs()
{
	queue<pair<int, int>> pq;
	pq.push({ i,j });
	check[i][j] = true;

	while (pq.size())
	{
		step++;
		pair<int, int> t = pq.front();
		cout << t.first << " " << t.second << endl;
		cout << step << endl;
		pq.pop();
		if (t.first == x2 && t.second == y2)
		{
			cout << "done" << endl;
			flag = 1;
			break;
		}
		for (int k = 0; k < 4; k++)
		{
			int x = i + dx[k];
			int y = j + dy[k];
			if (x >= 1 && x <= n && y >= 1 && y <= m && maps[x][y] == '.' && !check[x][y])
			{
				pq.push({ x,y });
				check[x][y] = true;
			}
		}
	}

	return;

}

int main()
{
	cin >> n >> m;

	cin >> x1 >> y1 >> x2 >> y2;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> maps[i][j];

	Bfs();
	if (flag)
		cout << step << endl;
	else
		cout << -1 << endl;


	return 0;
}